<script>
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
    console.log(xhr.readyState);
  };
  console.log(xhr.readyState);
  xhr.open('GET', 'test.php');
  xhr.send();
</script>